
/*
    发布消息客户端
*/
#include "mq_connection.hpp"


int main(int argc,char* argv[])
{
    //1.声明一个异步工作线程
    xgmq::AsyncWorker::ptr worker=std::make_shared<xgmq::AsyncWorker>();
    //2.实例化连接对象
    xgmq::Connection::ptr con=std::make_shared<xgmq::Connection>("127.0.0.1",8085,worker);
    //3.通过连接创建信道
    xgmq::Channel::ptr channel=con->createChannel();

    //4,接下来的服务通过信道完成
    //声明交换机
    google::protobuf::Map<std::string, std::string> tmp_arg;
    channel->declareExchange("exchange1",xgmq::ExchangeType::FANOUT,true,false,tmp_arg);
    //声明两个队列
    channel->declareQueue("queue1",true,false,false,tmp_arg);
    channel->declareQueue("queue2",true,false,false,tmp_arg);
    //将交换机与队列进行绑定
    channel->queueBind("exchange1","queue1","queue1");
    channel->queueBind("exchange1","queue2","news.music.#");

    //发布消息
    for(int i=0;i<10;i++)
    {
        channel->basicPublish("exchange1",nullptr,"hello-world"+std::to_string(i));
    }
    //关闭信道
    con->closeChannel(channel);
    return 0;
}